<?php
function getDateFormat($date_org){
	$date = split(" ",$date_org);
	$date = split("-",$date['0']);
	$d = $date['2'];
	$m = $date['1'];
	$y = $date['0'];//+543; //--beerz
	return $d.'-'.$m.'-'.$y;
}
function getDateFormat2($date_org){
	$datetime = split(" ",$date_org);
	$date = split("-",$datetime['0']);
	$d = $date['2'];
	$m = $date['1'];
	$y = $date['0'];//+543; //--beerz
	$time = split(":",$datetime['1']);
	return $d.'-'.$m.'-'.$y.' '.$time['0'].':'.$time['1'].' น.';
}

function getImgUrl($dimension,$id,$type,$mode){
		if(!$id || !$type)return;
		$image_hash = $dimension . '/' . $mode . '/' . $id . '.' . md5(SECURITY. $mode. $id . $type . $dimension .SITENAME ) . '.' . $type;
		return PATH. $image_hash;
}

function replaceImage($image){
	return str_replace("[UPLOAD_URL]",UPLOAD_URL,$image);
}
function replaceImage2($image){
	return str_replace("[UPLOAD_URL]",UPLOAD_PATH,$image);
}
function replaceQuotes($data){
	if (!get_magic_quotes_gpc())
		return htmlspecialchars($data,ENT_QUOTES);
	else return $data;
}
function replaceQuotes2($data){
	if (get_magic_quotes_gpc())
		return stripcslashes($data);
	else return $data;
}
function replaceQuotes3($data){
	$data = preg_replace('/"/i','\"',$data);
	$data = preg_replace('/“/i','\"',$data);
	$data = preg_replace('/\'/i',"\'",$data);
	/*$quotes = array('/"/',"/'/","/“/","/”/");
	$replacements = array('&#34;',"&quot;",'&#34;','&#34;');
	$data = preg_replace($quotes,$replacements,$data);*/
	return $data;
}
function DateSql($date){
	if(!$date) return;
	if($date=="0000-00-00" || $date == "00-00-0000") return;
	list($d,$m,$y) = explode("-",$date);
	return $y."-".$m."-".$d;
}

function _print($data) {
    if ($data) {
        if (is_array($data) OR is_object($data)) {
            echo "<pre>\n";
            print_r($data);
            echo "</pre>\n";
        } else if(is_bool($data)) {
            var_dump($data);
        } else {
            echo "{$data}<br />\n";
        }
    } else {
        echo "Data is empty\n";
    }
}

function unescape($str) {
    if(!$str)return;
    $str = preg_replace("/%u([0-9a-f]{3,4})/i","&#x\\1;",urldecode($str));
    return html_entity_decode($str,null,'UTF-8');;
}
function getThaiday($enDay){
	switch ($enDay){
		case 'Sunday': $thDay = 'อาทิตย์'; break;
		case 'Monday': $thDay = 'จันทร์'; break;
		case 'Tuesday': $thDay = 'อังคาร'; break;
		case 'Wednesday': $thDay = 'พุธ'; break;
		case 'Thursday': $thDay = 'พฤหัสบดี'; break;
		case 'Friday': $thDay = 'ศุกร์'; break;
		case 'Saturday': $thDay = 'เสาร์'; break;
	}
	return $thDay;
}
function getToday(){
	$today = date('l d m Y H:i', mktime(date("H"), date("i"), date("s"), date('m'), date('d'), date('Y')));
	$date = split(' ', $today);
	//$day = getThaiday($date['0']);
	//$year = $date['3']+543;
	//$cur_date = 'วัน'.$day.'ที่ '.$date['1'].'-'.$date['2'].'-'.$year.' เวลา '.$date['4'].' น.';
	$day = $date['0'];
	$year = $date['3'];
	$cur_date = $day.' '.$date['1'].'-'.$date['2'].'-'.$year.' '.$date['4'];
	return $cur_date;
}
function getHour(){
	for($i=0; $i<24; $i++){
		if($i<10)
			$hour[] = '0'.$i;
		else
			$hour[] = $i;
	}
	return $hour;
}
function getMin(){
	for($i=0; $i<60; $i++){
		if($i<10)
			$min[] = '0'.$i;
		else
			$min[] = $i;
	}
	return $min;
}
?>